Fix: Preserve nested arrays and objects in array encoding (Issue #6)#7
Merged
VinciGit00 merged 1 commit intomainfrom Nov 13, 2025
Merged
Fix: Preserve nested arrays and objects in array encoding (Issue #6)#7VinciGit00 merged 1 commit intomainfrom
VinciGit00 merged 1 commit intomainfrom
Conversation
- Modified is_uniform_array_of_objects() to return None when objects contain non-primitive fields - Arrays with nested objects/arrays now use list format instead of tabular format - This ensures all data is preserved during encoding/decoding - Added comprehensive test suite for nested structures - All 107 existing tests pass without regression Fixes #6
|
🎉 This PR is included in version 1.5.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes issue #6 where nested objects and arrays within tabular arrays were being lost during the toonification process.
Problem
When encoding arrays of objects that contained non-primitive fields (nested arrays or objects), only the primitive fields were preserved in the tabular format. Non-primitive fields like
hierarchy(array of strings) andoffset(array of objects) were silently dropped.Solution
Modified the
is_uniform_array_of_objects()function intoon/utils.pyto:Noneif any non-primitive field is foundThe list array format properly handles nested structures and preserves all data.
Changes
toon/utils.py: Enhancedis_uniform_array_of_objects()to detect non-primitive fieldstests/test_nested_arrays.py: Added comprehensive test suite with 5 new tests covering:Testing
Trade-offs
While this fix ensures data preservation, arrays with nested fields will now use the list format instead of the more compact tabular format. This is the correct behavior since the tabular format cannot represent nested structures without data loss.
Fixes #6